<?php
require_once 'config/dbConnect.php';
require_once 'classes/userClass.php';
function initiate(){
	$loggedIn = false;
	if(isset($_SESSION['userName'])){
		$loggedIn = true;
	}
	
	if(isset($_COOKIE['authKey'])){
		if($loggedIn === false){
			$authKeyQuery = "SELECT userName, passWord FROM user WHERE authKey=:authKey";
			$authKeyQuery = $db -> prepare($authKeyQuery);
			$authKeyQuery -> bindParam(':authKey', $authKeyQuery);
			$authKeyQuery -> execute();
			$authKeyQuery = $authKeyQuery -> fetch();
			if(!isset($authKeyQuery['userName'])){
				setcookie("authKey", "", time() - 3600);
			}else{
				$user = new user($db, $authKeyQuery['userName'], $authKeyQuery['passWord']);
			}
		}else{
			setcookie("authKey", "", time() - 3600);
		}
	}
}

?>